<?php
/**
 *  NevuxBB - Free Forum Software
 *  Copyright (C) 2008, 2010 NevuxBB (No one specific author)*  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Login System
 * File: login.php
 * Purpose: Allow the user to login or recover their account
 * Todo: Finish writing it
 *
 */
require('system/files/global.php');

// start the initalisation of the login page
$core_template_system->setvar('page_title', 'Logout');

// be cautios, remove the cookie anyway
setcookie(session_name(), '', time() - 42000, '/');

// show the header loaded
$core_template_system->pparse();

// include the language file for this page
$core_lang_system->reset();
$core_lang_system->add_file('login');

// build the menu
$core_template_system->setvar('breadcrumb', $core_nav_system->generateNav(array('settings' => array('level_down' => false,
																									'main_class' => 'menu'),
																				'information' => array('home' => array('data' => array(1 => 'Home',
																																	   2 => 1))))));

// start the page
if(!CoreUserSystem::isLoggedIn()) {
	// user is already logged out
	$core_template_system->setvar('error_message', $core_lang_system->get_var('ALREADY_LOGGED_OUT', 3));
	$core_template_system->setvar('error', $core_lang_system->get_var('ERROR', 4));
	$core_template_system->setvar('back_url', 'index.php');
	
	// render the page
	$core_template_system->newTemplate(BASE_PATH . '/templates/' . ForumSettings::getCurrentTemplate() . '/error.html');
	$core_template_system->pparse();
} else {
	// log the user out
	BaseUserSystem::logout();
	
	// page variables
	$core_template_system->setvar('click_redirection_message', $core_lang_system->get_var('CLICK_REDIRECTION', 4));
	$core_template_system->setvar('redirection_message', $core_lang_system->get_var('CURRENT_REDIRECTION', 4));
	$core_template_system->setvar('url_to_go_to', 'index.php');
	$core_template_system->setvar('redirection', $core_lang_system->get_var('REDIRECTION', 4));
	
	// render the page
	$core_template_system->newTemplate(BASE_PATH . '/templates/' . ForumSettings::getCurrentTemplate() . '/redirection.html');
	$core_template_system->pparse();
}

require('system/files/footer.php');
?>